package cn.doitedu.profile.ml.knn;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Image2VecUtil {

    public static void main(String[] args) throws IOException {

        File samples = new File("profile/data/knn/test");
        File[] sampleFiles = samples.listFiles();


        BufferedWriter bw = new BufferedWriter(new FileWriter("profile/data/knn/test_vec/test_vec.txt"));


        for (File sampleFile : sampleFiles) {
            BufferedImage img = ImageIO.read(sampleFile);
            StringBuffer sb = new StringBuffer();
            sb.append(sampleFile.getName().split("_")[1]).append("_");

            for(int i=0;i<32;i++){
                for(int j=0;j<32;j++){
                    int rgb = img.getRGB(j, i);
                    if(rgb==-1){
                        sb.append("0").append(",");
                    }else{
                        sb.append("1").append(",");
                    }
                }
            }

            bw.write(sb.toString());
            bw.newLine();

        }

        bw.close();



    }

}
